// pages/customer/cardBag/cardBag.js
Page({
  data: {

  },
  onLoad: function (options) {

  },
  // 赠送卡券
  sendCard(e) {
    this.setData({
      sell_card: true,
      card_number: e.currentTarget.dataset.cid,
      card_password: e.currentTarget.dataset.cpwd,
      goods_name: e.currentTarget.dataset.cgn,
      goods_type: e.currentTarget.dataset.cgt,
      card_id: e.currentTarget.dataset.id,
      card_url: e.currentTarget.dataset.curl
    })
  },
  // 分享提货卡
  onShareAppMessage: function (e) {
    if (e.from === 'button') {
      // 来自页面内转发按钮
      return {
        title: '送你一张提货卡，快来领取吧',
        path: 'pages/customer/card/card?card_number=' + this.data.card_number + '&card_password=' + this.data.card_password + '&goods_name=' + this.data.goods_name + '&goods_type=' + this.data.goods_type + '&card_url=' + this.data.card_url,
        imageUrl: 'https://i0.hdslb.com/bfs/album/3793af5ad62569b7b6e7b5ad2bfa0687cb56e477.jpg',
      }
    }
  },
  // 更新卡券信息
  updateCard() {
    // 更新卡券信息status=2,待提货
    wx.showLoading({
      title: '系统正在处理',
    });
    this.setData({
      sell_card: false
    });
    wx.cloud.callFunction({
      name: "updateCards",
      data: {
        card_id: this.data.card_id,
        status: 2
      },
      success: res => {
        wx.hideLoading();
        console.log('this.data.card_id:' + this.data.card_id);
        console.log(res);
        if (res.result.stats.updated == 1) {
          console.log('卡券更新状态2成功');
          wx.removeStorageSync('lssue_list');
          wx.removeStorageSync('lssue_length');
          this.tabGetlssueCards();
        }
      },
      fail: res => {
        wx.hideLoading();
        wx.showToast({
          title: '更新状态失败',
          icon: 'error'
        }, 2000);
        console.log('卡券更新状态2失败');
      }
    })
  },
  // 隐藏模态框
  hideModal(e) {
    this.setData({
      sell_card: false
    })
  },
})